package nc.bs.test.impl;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.naming.NamingException;

import nc.bs.pub.DataManageObject;
import nc.itf.test.imanager.IManager;

public class Manager extends DataManageObject implements IManager{

	public Manager() throws NamingException{
		super();
	}

	public Object getObjById(int i,Object o) throws Exception{
		if(i==1){
			return nc.bs.framework.common.RuntimeEnv.getInstance().getNCHome();
		}
		else if (i==2) {
			String xmlPath=String.format("%1$s%2$sierp%2$sbin%2$sspring.xml",nc.bs.framework.common.RuntimeEnv.getInstance().getNCHome(),nc.bs.framework.ServiceConfig.getFileSeparator());
			return InputStreamToByte(new FileInputStream(xmlPath));
		}		
		return null;
	}
	private byte[] InputStreamToByte(InputStream is) throws IOException {
		ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
		int ch;
		while ((ch = is.read()) != -1) {
			bytestream.write(ch);
		}
		byte data[] = bytestream.toByteArray();
		bytestream.close();
		return data;
	}
}
